<%@ include file="/common/taglibs.jsp"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.probiz.estore.common.model.system.LoginEntry,com.probiz.estore.core.util.CacheUtil,java.util.*" %>
<html>
<head>
	<%
		LoginEntry entry=(LoginEntry)CacheUtil.getInstance().getLoginErrorCache(request.getRemoteAddr());
		//有错
		String error=request.getParameter("error");
		//验证码错
		String errorCode=request.getParameter("errorCode");
	
		if(entry==null&&(errorCode!=null||error!=null)){
			entry=new LoginEntry();
			entry.setVisitedTimes(1);
			entry.setIp(request.getRemoteAddr());
			entry.setVisitedDateTime(new Date());
			CacheUtil.getInstance().setLoginErrorCache(request.getRemoteAddr(),entry);
		}else if(errorCode!=null||error!=null){
			entry.setVisitedTimes(entry.getVisitedTimes()+1);
		}
		request.setAttribute("entry",entry);
		
		boolean isCodeEnabled=com.probiz.estore.common.helper.ConfigUtil.getInstance().getIsValidationCodeEnabled();
		request.setAttribute("isCodeEnabled",new Boolean(isCodeEnabled));
	%>
</head>
<body class="login_b">
<c:set var="maxFailTimes" value="${applicationScope.appConfig.maxLoginFailTimes}" scope="page"/>
<form class="loginForm" method="post" name="loginForm" id="loginForm" action="${ctxPath}/j_security_check"
	onsubmit="return validateForm(this)">
<div class="login">
	<div class="img"><img src="${ctxPath}/images/layout/login_logo.gif" width="318" height="81" /></div>
	<div class="txt">
		<c:if test="${empty param.errorCode}">
			<c:if test="${param.error != null}">
				<c:set var="errorMsg">
				<div class="warning_msg" id="loginError"><p class="cont"><fmt:message key="errors.password.mismatch" /></p></div>
				</c:set>
			</c:if>
		</c:if>
		<c:if test="${param.errorCode=='true'}">
			<c:set var="errorMsg">
			${errorMsg}
			<div class="warning_msg"><p class="cont"><fmt:message key="login.error.validationcode"/></span></p></div>
			</c:set>
			<c:remove var="errorFlag" scope="session"/>
		</c:if>
		<c:if test="${not empty entry}">
			<c:if test="${entry.visitedTimes eq maxFailTimes}">
				<c:set var="errorMsg">
				${errorMsg}
				<div class="warning_msg"><p class="cont"><fmt:message key="login.error.loginTimes"><fmt:param value="${entry.visitedTimes}"/></fmt:message></p>
				</div>
				</c:set>
			</c:if>
			<c:if test="${entry.visitedTimes gt maxFailTimes}">
				<c:redirect url="http://www.probiz.com"/>
			</c:if>
		</c:if>
		${errorMsg}
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
						<th><fmt:message key="appAdmin.username" /></th>
						<td colspan="2"><input id="j_username" name="j_username" type="text" class="inputtxt2" style="width:190px" tabindex="1" validConf="required"/></td>
				</tr>
				<tr>
						<th><fmt:message key="login.input.password" /></th>
						<td colspan="2"><input id="j_password" name="j_password" type="password" class="inputtxt2" style="width:190px" tabindex="2" validConf="required"/></td>
				</tr>
				<c:if test="${isCodeEnabled=='true'}">
				<tr>
						<th><fmt:message key="login.input.validationCode"/></th>
						<td>
							<span>
							<input autocomplete="off" name="validationCode" type="text" class="inputtxt2" style="width:80px" tabindex="3" validConf="required"/>
							<img id="imgValidationCode" src="${ctxPath}/loginCode.html" alt="<fmt:message key="login.validateCode"/>" />
							</span>
							<a href="javascript:void();" onclick="return refreshImage()" title="<fmt:message key="login.image.changeTip"/>"><fmt:message key="login.image.change"/></a>
						</td>
				</tr>
				</c:if>
				<c:if test="${applicationScope.appConfig.isRememberMeEnabled}">
				<tr>
						<th>&nbsp;</th>
						<td>
							<input type="checkbox" name="rememberMe" id="rememberMe" tabindex="4" />
      						<label for="rememberMe"><fmt:message key="login.rememberMe" /></label>
						</td>
				</tr>
				</c:if>
				<tr>
						<th>&nbsp;</th>
						<td><input name="" type="submit" class="input_login" value=""/></td>
				</tr>
		</table>
	</div>
</div>
</form>
<script type="text/javascript">
	$j(document).ready(function(){
		resetForm();
		autoApplyValidate(document.getElementById("loginForm"));
	});	
	
	function refreshImage(){
		$('imgValidationCode').src="${ctxPath}/loginCode.html?rand="+parseInt(1000*Math.random());
		return false;
	}

	function resetForm(){
		var form=$("loginForm");
		if (getCurrentUserName() != null && getCurrentUserName() != ""){
			form.j_username.value=getCurrentUserName();
			form.j_password.value="";
			form.j_password.focus();
		}else{
			form.j_username.value="";
			form.j_password.value="";
			form.j_username.focus();
		}
	}
</script>
</body>
</html>